<?php

namespace App\Providers;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\ServiceProvider;


class AppServiceProvider extends ServiceProvider
{
    /**
     * Bootstrap any application services.
     * @param Request $request\
     * @return void
     */
    public function boot(Request $request)
    {
//      日志记录sql 语句 和 请求参数
        if($request->input("debug",1) == 1){
            Log::channel('sqlLog')->info('用户请求数据:',$request->all());
            DB::listen(function($query) {
                $bindings = $query->bindings;
                if($bindings){
                    Log::channel('sqlLog')->info(' execution time: '.$query->time.'ms; '.$query->sql.': params:'.json_encode($bindings));
                }else{
                    Log::channel('sqlLog')->info(' execution time: '.$query->time.'ms; '.$query->sql);
                }

            });
        }
    }

    /**
     * Register any application services.
     *
     * @return void
     */
    public function register()
    {
        //$this->app->register(UserServiceProvider::class);
        //$this->app->register(OrderServiceProvider::class);
        //$this->app->register(TestServiceProvider::class);
    }
}
